import Vue from 'vue'

export function insertData(data) {
    return new Promise((resolve, reject) => {
        Vue.prototype.$db.insert(data,function (err,newInvoice) {
            // console.log(666,newInvoice)
            resolve(err)
        })
    })
}

export function payMethodData(data) {
    return new Promise((resolve, reject) => {
        Vue.prototype.$payMethod.find(data,function (err,payMethod) {
            // console.log(666,newInvoice)
            resolve(payMethod)
        })
    })
}

export function payMethodItemData(data) {
    return new Promise((resolve, reject) => {
        Vue.prototype.$payMethodItem.find(data,function (err,payMethodItem) {
            // console.log(666,newInvoice)
            resolve(payMethodItem)
        })
    })
}

export function payTypeData(data) {
    return new Promise((resolve, reject) => {
        Vue.prototype.$payType.find(data,function (err,$payType) {
            // console.log(666,newInvoice)
            resolve($payType)
        })
    })
}

export function receiptData(data) {
    return new Promise((resolve, reject) => {
        Vue.prototype.$receipt.find(data,function (err,$receipt) {
            // console.log(666,newInvoice)
            resolve($receipt)
        })
    })
}

export function findList(data,startPages,pageSize) {
    return new Promise((resolve, reject) => {
        Vue.prototype.$db.find(data).sort({"createAt":-1})
            .skip(startPages).limit(pageSize)
            .exec(function (err, results) {
                resolve(results);
            });
    })
}

export function count(data) {
    return new Promise((resolve, reject) => {
        Vue.prototype.$db.count(searchParam,function (err, count) {
            console.log('[count err]',err)
            resolve(count);
        })
    })
}